package com.sinothk.view.refresh.demo

import android.os.Bundle
import android.os.Handler
import androidx.appcompat.app.AppCompatActivity
import com.sinothk.banner.nice.Banner
import com.sinothk.banner.nice.BannerConfig
import com.sinothk.banner.nice.Transformer
import com.sinothk.view.xrefresh.XRefreshLayout
import com.sinothk.view.xrefresh.listener.RefreshHandler
import com.sinothk.view.xrefresh.widget.classics.FooterView
import com.sinothk.view.xrefresh.widget.classics.HeaderView
import com.sinothk.view.xrefresh.widget.progressBar.ProgressStyle2Bar

class XRefreshDemoMainActivity2 : AppCompatActivity() {
    var bannerView: Banner? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main2)

        val xRefreshLayout: XRefreshLayout = findViewById(R.id.xRefreshLayout)
        bannerView = findViewById(R.id.bannerView)


        val headerView = HeaderView(this, R.color.bg, R.color.graye)
        //        HeaderView headerView = new HeaderView(this, R.color.bg, R.color.graye, R.drawable.refresh_progress_style_img);
        xRefreshLayout.setHeaderView(headerView)
        val footerView = FooterView(this, R.color.bg, R.color.graye, ProgressStyle2Bar(this))
        xRefreshLayout.setFooterView(footerView)

        xRefreshLayout.setRefreshEnable(true)
        xRefreshLayout.setLoadMoreEnable(false)

//        public class CustomView extends QLoadView
//        public class CustomView implements ILoadView

//        qrefreshLayout.setHeaderView(new CustomView());
//        qrefreshLayout.setFooterView(new CustomView());
        xRefreshLayout.setRefreshHandler(object : RefreshHandler {
            override fun onRefresh(refresh: XRefreshLayout) {
                Handler().postDelayed({ runOnUiThread {
                    xRefreshLayout.refreshComplete()
                    xRefreshLayout.setRefreshEnable(false)

                } }, 3000)
            }

            override fun onLoadMore(refresh: XRefreshLayout) {
                Handler().postDelayed({ runOnUiThread { xRefreshLayout.loadMoreComplete() } }, 3000)
            }
        })

        initBannerView()
    }

    /**
     * 轮播图
     */
    private fun initBannerView() {
        val bannerList: ArrayList<CustomData> = ArrayList()

        for (index in 0..3) {
            bannerList.add(CustomData("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1595236098567&di=514e6af615e9696c8dfcdca2333b7bc4&imgtype=0&src=http%3A%2F%2Ft9.baidu.com%2Fit%2Fu%3D2268908537%2C2815455140%26fm%3D79%26app%3D86%26f%3DJPEG%3Fw%3D1280%26h%3D719"))
        }

        bannerView!!.setAutoPlay(true)
                .setPages(bannerList, CustomViewHolder())
                .setBannerStyle(BannerConfig.CIRCLE_INDICATOR)
                .setBannerAnimation(Transformer.Default)
                .setDelayTime(3000)
                .start()

        bannerView!!.setOnBannerClickListener { _, position ->

        }
    }
}